package com.mybatis.lo.factory;

import com.mybatis.lo.config.Configuration;
import com.mybatis.lo.constant.ExecutorType;
import com.mybatis.lo.executor.Executor;
import com.mybatis.lo.sqlsession.DefaultSqlSession;
import com.mybatis.lo.sqlsession.SqlSession;
import lombok.AllArgsConstructor;

/**
 * SqlSessionFactory的默认实现
 * @author zhangbh
 * 2023-06-15 08:41
 **/
@AllArgsConstructor
public class DefaultSqlSessionFactory implements SqlSessionFactory {

    private Configuration configuration;

    @Override
    public SqlSession openSession() {
        ExecutorType executorType = configuration.getDefaultExecutorType();
        return openSession(executorType);
    }

    @Override
    public SqlSession openSession(ExecutorType executorType) {
        Executor executor = configuration.newExecutor(executorType);
        return new DefaultSqlSession(configuration, executor);
    }
}
